﻿using System;
using System.Windows.Forms;
using Assist;

namespace HYSump.Forms
{
	internal class HYintComBox : YJKComboBox
	{
		protected override void OnKeyUp(KeyEventArgs e)
		{
			if (e.Modifiers == Keys.Tab)
			{
				return;
			}
			if (base.Text.Length == 1 && e.KeyValue == 96)
			{
				base.Text = "";
			}
			base.OnKeyUp(e);
		}

		protected override void OnKeyPress(KeyPressEventArgs e)
		{
			if (!char.IsDigit(e.KeyChar) && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
			base.OnKeyPress(e);
		}

		protected override void OnGotFocus(EventArgs e)
		{
			base.OnGotFocus(e);
			if (this.Text.Trim() != "")
			{
				this.oldValue = this.Text;
			}
		}

		protected override void OnLeave(EventArgs e)
		{
			if (this.Text.Trim() == "")
			{
				MessageBox.Show("参数不能为空", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				this.Text = this.oldValue;
				base.Focus();
			}
			base.OnLeave(e);
		}

		private string oldValue = "0";
	}
}
